package com.xnj.transform_stream;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

// 字符输出转换流
public class OutputStreamWriterTest {
    public static void main(String[] args) {
        try(
                // 1. 创建一个字节输出流对象
                FileOutputStream os = new FileOutputStream("src/transformout.txt");
                // 2. 创建一个字符输出转换流对象, 指定字符集GBK
                OutputStreamWriter osw = new OutputStreamWriter(os,"GBK");
                // 3. 使用字符输出缓冲流对象，写入数据
                BufferedWriter bw = new BufferedWriter(osw);
                ){
            bw.write("abc你好hh");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
